package com.aspose.cells;

import java.util.HashMap;
import java.util.Iterator;

class zafd {
   public static HashMap a = new HashMap();

   public zafd() {
      a.clear();
   }

   public void a(String var1, Workbook var2, LoadOptions var3) throws Exception {
      zafc var4 = null;
      if (var3 != null && var3 instanceof HTMLLoadOptions) {
         var2.getSettings().a(((HTMLLoadOptions)var3).getEncoding());
         var4 = new zafc(var1, var2, (HTMLLoadOptions)var3, Encoding.getUTF8());
      } else {
         String var5 = this.a(var1);
         if (var5 == null) {
            var4 = new zafc(var1, var2, var2.getSettings().f());
         } else {
            var4 = new zafc(var1, var2, Encoding.getEncoding(var5));
         }
      }

      var4.m();
      var4.k().a();
      var4.q().e().z();
      if (this.a(var4)) {
         var4.a(var4.q(), var2, var2.getSettings().f());
      }

      a.clear();
   }

   public void a(com.aspose.cells.b.a.d.zm var1, Workbook var2, LoadOptions var3) throws Exception {
      try {
         zafc var4 = null;
         if (var3 != null && var3 instanceof HTMLLoadOptions) {
            var2.getSettings().a(((HTMLLoadOptions)var3).getEncoding());
            var4 = new zafc(var1, var2, (HTMLLoadOptions)var3, Encoding.getUTF8());
         } else {
            String var5 = this.a(var1);
            if (var5 == null) {
               var4 = new zafc(var1, var2, new HTMLLoadOptions(), Encoding.getUTF8());
            } else {
               var4 = new zafc(var1, var2, new HTMLLoadOptions(), Encoding.getEncoding(var5));
            }
         }

         var4.m();
         var4.q().e().z();
         if (this.a(var4)) {
            var4.a(var4.q(), var2, var2.getSettings().f());
         }
      } finally {
         if (var1 != null) {
            var1.a();
         }

      }

   }

   private boolean a(zafc var1) {
      Iterator var2 = var1.q().d().values().iterator();

      com.aspose.cells.b.a.d.zm var3;
      do {
         if (!var2.hasNext()) {
            return false;
         }

         var3 = (com.aspose.cells.b.a.d.zm)var2.next();
      } while(var3 == null);

      return true;
   }

   private String a(String var1) throws Exception {
      com.aspose.cells.b.a.d.ze var2 = com.aspose.cells.b.a.d.zd.a(var1, 3, 1, 3);
      return this.a((com.aspose.cells.b.a.d.zm)var2);
   }

   private String a(com.aspose.cells.b.a.d.zm var1) throws Exception {
      com.aspose.cells.b.a.d.zn var2 = new com.aspose.cells.b.a.d.zn(var1);
      String var3 = null;
      int var4 = 0;

      for(String var5 = null; (var5 = var2.f()) != null && var4 <= 5; ++var4) {
         int var6 = var5.indexOf("charset");
         if (var5.trim().startsWith("<meta") && var6 > -1) {
            String var7 = var5.substring(var6, var6 + (var5.length() - var6 - 1));
            var3 = var7.trim().substring(var7.indexOf("=") + 1);
            var3 = com.aspose.cells.b.a.zv.a(var3, "\"", "");
            var3 = com.aspose.cells.b.a.zv.a(var3, "/", "");
            break;
         }
      }

      var1.b(0L);
      return var3;
   }
}
